package com.roy.sms;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.roy.sms.model.User;

public class AuthInterceptor extends HandlerInterceptorAdapter {
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		
		String reqUri = request.getRequestURI();
		if(reqUri.indexOf("/site/") == -1 ){
			HttpSession session = request.getSession();
			User user = (User)session.getAttribute("loginUser");
			if(user==null) {
				response.sendRedirect(request.getContextPath()+"/site/login.do");
				return false;
			}
		}
		return super.preHandle(request, response, handler);
	}
}
